﻿
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Layout1.cshtml";
}

<style>
    .row > label, .row > div {
        display: inline-block;
    }
</style>

<article class="cl pd-20">
    <form action="@Url.Action("Add_Per","Houses")" method="post" class="form form-horizontal" id="form">
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>区域：</label>
            <div class="formControls col-2">
                <span class="select-box">
                    @Html.DropDownList("RegionId", ViewBag.RegionList as List<SelectListItem>, "==请选择==", new { @class = "select" })
                </span>
            </div>
            <label class="form-label col-2">小区：</label>
            <div class="formControls col-2">
                <select class="select" id="sel_CommunityId" name="CommunityId">
                    <option>==请选择==</option>
                </select>
            </div>
            <label class="form-label col-1">房型：</label>
            <div class="formControls col-2">
                @Html.DropDownList("RoomTypeId", ViewBag.RoomTypeList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">地址：</label>
            <div class="formControls col-5">

                <input type="text" class="input-text" placeholder="详细地址" name="Address" datatype="*" nullmsg="地址不能为空">
            </div>
            <label class="form-label col-2">月租金：</label>
            <div class="formControls col-2 skin-minimal">
                <input type="text" class="input-text" name="MonthRent" datatype="n" nullmsg="租金不能为空">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-2">
                <span class="select-box">
                    @Html.DropDownList("StatusId", ViewBag.StatusList as List<SelectListItem>, "==请选择==", new { @class = "select" })
                </span>
            </div>
            <label class="form-label col-2">面积：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" placeholder="平米" name="Area" datatype="n" nullmsg="面积不能为空">
            </div>
            <label class="form-label col-1">装修：</label>
            <div class="formControls col-2 skin-minimal">
                @Html.DropDownList("DecorateStatusId", ViewBag.DecorateStatusList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2"><span class="c-red">*</span>楼层：</label>
            <div class="formControls col-1">
                <input type="text" class="input-text" placeholder="所在层" name="FloorIndex" datatype="n" nullmsg="请填写所在楼层">

            </div>
            <div class="formControls col-1">
                <input type="text" class="input-text" placeholder="总层数" name="TotalFloorCount" datatype="n" nullmsg="请填写总楼层">

            </div>

            <label class="form-label col-2">类别：</label>
            <div class="formControls col-2 skin-minimal">
                @Html.DropDownList("TypeId", ViewBag.TypeList as List<SelectListItem>, "==请选择==", new { @class = "select" })
            </div>

            <label class="form-label col-1">朝向：</label>
            <div class="formControls col-2 skin-minimal">
                <input type="text" class="input-text" name="Direction" datatype="*" nullmsg="朝向不能为空">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">可看房时间：</label>
            <div class="formControls col-2">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:180px;" name="LookableDateTime" datatype="*" nullmsg="看房时间不能为空">
            </div>
            <label class="form-label col-2">入住时间：</label>
            <div class="formControls col-2">
                <input type="text" name="CheckInDateTime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'datemin\')}'})" id="datemax" class="input-text Wdate" style="width:180px;" datatype="*" nullmsg="入住时间不能为空">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">业主姓名：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" name="OwnerName" datatype="*" nullmsg="业主姓名不能为空">
            </div>
            <label class="form-label col-2">业主电话：</label>
            <div class="formControls col-2">
                <input type="text" class="input-text" name="OwnerPhoneNum" datatype="m" nullmsg="请填写电话">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-2">房源描述：</label>
            <div class="formControls col-9">
                @*<textarea class="textarea" name="Description" datatype="*" nullmsg="房源描述也要写的"></textarea>*@

                <!-- 加载编辑器的容器 -->
                <script id="HouseDescription" name="Description" type="text/plain">

                </script>

            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-2">配置设置：</label>
            <div class="formControls col-8">
                @foreach (var item in Model)
                {
    <input type="checkbox" id="AttachmentId_@item.Id" name="AttachmentIds" value="@item.Id" />
                    <label for="AttachmentId_@item.Id">@item.Name</label>}
            </div>
        </div>

        <div class="row cl">
            <div class="col-10 col-offset-2">
                <button class="btn btn-primary radius" type="button" id="btn_Save"><i class="Hui-iconfont">&#xe632;</i> 保存</button>

            </div>
        </div>

    </form>
</article>
@section footScript
{
    <script src="~/Content/h-ui/lib/Validform/5.3.2/Validform.min.js"></script>
    <script src="~/Content/ueditor/1.4.3/ueditor.config.js"></script>
    <script src="~/Content/ueditor/1.4.3/ueditor.all.min.js"></script>
    <script src="~/Content/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
    <script src="~/Content/My97DatePicker/WdatePicker.js"></script>
    <script>

        $(function () {

            //实例化编辑器
            var ue = UE.getEditor('HouseDescription');

            //对用户输入的信息进行校验
            //初始化验证插件
            var validform = $("#form").Validform({ tiptype: 2 });

            $("#btn_Save").click(function () {

                var formObj = $("#form").serializeArray();

                //当验证通过的时候发送ajax请求
                if (validform.check(false)) {

                    $.post("@Url.Action("Add_Per", "Houses")", formObj, function (data) {
                        if (data.State == 1) {
                            //弹出提示信息
                            layer.msg('添加成功', { icon: 1 });
                            //关闭遮罩层
                            //刷新列表
                            parent.location.reload();
                        }
                        else {
                            layer.msg(data.ErrorMessage, { icon: 5 });
                        }

                    }, "json");
                }

            });


            //区域-小区联动
            $("#RegionId").change(function () {
                //获取当前选择的Id
                var regionId = $(this).val();
                if (regionId) {
                    //发送ajax请求获取小区信息
                    $.post("@Url.Action("GetCommunities", "Houses")", { regionId: regionId }, function (data) {

                        //清空现有的校区信息
                        $("#sel_CommunityId").empty();

                        //添加新的option
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            var option = "<option value=" + item.Id + ">" + item.Name + "</option>";

                            $("#sel_CommunityId").append(option);
                        }
                    }, "json");
                }
            });

        });

    </script>
}
